package com.itheima.a04test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test2 {
    public static void main(String[] args) {
        //班级里有n个学生，要求70%随机到男生，30%随机到女生

        //思路：依旧是学生对象存入集合，男生女生分开存，先在1~10随机
        //其中1~7在男生集合里面再次随机，8~10就。。。

        //创建两个集合
        ArrayList<Student> boyList =new ArrayList<>();
        ArrayList<Student> girlList =new ArrayList<>();

        //创建学生对象
        Student s1=new Student("zhangsna",19);
        Student s2=new Student("lisi",21);
        Student s3=new Student("wangewu",23);
        Student s4=new Student("zhaoliu",24);
        Student s5=new Student("wanger",20);
        Student s6=new Student("mazi",66);

        //添加学生对象
        Collections.addAll(boyList,s1,s2,s3);
        Collections.addAll(girlList,s4,s5,s6);

        //先随机男生还是女生
        Random r=new Random();
        int i = r.nextInt(10)+1;

        //判断
        if(i>=1&&i<=7){
            //随机到男生，开始在男生里面随机
            int b=r.nextInt(boyList.size());
            //输出姓名
            System.out.println(boyList.get(b).getName());
        }else if(i>=8&&i<=10){
            //随机到女生，开始在女生里面随机
            int g=r.nextInt(girlList.size());
            //输出姓名
            System.out.println(girlList.get(g).getName());
        }

        System.out.println("------------");
    }
}
